package models

import (
	"gitee.com/sansaniot/ssiot-core/httpmvc/model"

	cDto "ssdevice/common/dto"
	"ssdevice/internal/device/models/query"
)

type SysSvc struct {
	Id           string         `json:"id" gorm:"primaryKey"`
	Name         string         `json:"name"`
	Key          string         `json:"key"`
	Version      string         `json:"version"`
	Path         string         `json:"path"`
	Arg          string         `json:"arg"`
	Ip           string         `json:"ip"`
	Machine      string         `json:"machine"`
	InstanceId   string         `json:"instanceId"`
	Bin          string         `json:"bin"`
	CreateTime   cDto.LocalTime `json:"createTime"`
	UpdateTime   cDto.LocalTime `json:"updateTime"`
	RegisterTime cDto.LocalTime `json:"registerTime"`
	LoginTime    cDto.LocalTime `json:"loginTime"`
	model.Model
}

func (s *SysSvc) TableName() string {
	return "sys_svc"
}

func (s *SysSvc) Generate() interface{} {
	o := *s
	return &o
}

func (s *SysSvc) FindSvcList(req *query.SysSvcQuery) (list []SysSvc, err error) {
	err = s.FindList(&list,
		cDto.MakeCondition(req.GetNeedSearch()),
		cDto.OrderDest("create_time", true, req.OrderBy),
	)
	return
}

func (s *SysSvc) GetByInstanceId(instanceId string) error {
	return s.FindOne(s, cDto.MakeCondition(query.SysSvcQuery{InstanceId: instanceId}))
}
